<?php

/**
 * @author 陈韵
 * 中远国际创建订单
 */
namespace App\Service\OrderService\OrderRouteService;
use App\Service\Code\Normal;
use App\Service\OrderService\BaseSupplierRouterService;
use App\Service\VendorClient\Shopzhongyuan\ShopzhongyuanApiClient;
use App\Service\TraitService\SupplierRouterOrderTrait;
use App\Model\CommodityModel\SupplierCommodity;

class Shopzhongyuan extends BaseSupplierRouterService
{
    use SupplierRouterOrderTrait;
    
    /**
     * 订单申报
     * @param array $param
     * @return mixed
     */
    public function orderPay( $param = [] )
    {
       $supplier_skuids = array_column($param['orderGoods'],'supplier_skuid');
       $supplier_skuids_map = SupplierCommodity::instance()->whereIn('ID',$supplier_skuids)->select(['ID','SupplierCommodityKey'])->get()->toArray();
       if(empty($supplier_skuids_map)){
           return Normal::returnCode(Normal::FAIL,"没有查询到商品资料，请核实！");
       }
       $param['supplier_skuid_map'] = array_column($supplier_skuids_map,'SupplierCommodityKey','ID');
       return $this->callSdkApi(ShopzhongyuanApiClient::class,$param['apiBody'])->createOrder($param);
    }

    /**
     * 订单取消
     * @param array $param
     * @return mixed
     */
    public function orderCancel( $param = [] )
    {
        return Normal::returnCode(Normal::SUC,"处理完成");
    }
    
    /**
     * 订单售后
     * @param array $param
     * @return mixed
     */
    public function orderAfterSale($param = [])
    {
        return $this->callSdkApi(ShopzhongyuanApiClient::class,$param['apiBody'])->cancelOrder($param);
    }

    /**
     * 商品列表查询接口
     * @param array $param
     * @return mixed
     */
    public function queryGoodsList( $param = [] )
    {
       return Normal::returnCode(Normal::SUC,"处理完成");
    }
}